home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Applications… / Getting Started w⁄GX ƒ / Getting Started GX - misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  5.4 KB  |  250 lines  |  [TEXT/KAHL]

  1. /**
  2.  --
  3.  --        App:        Getting Started w/QD GX (WWDC)
  4.  --
  5.  -- 
  6.  --        Version:    1.0     4/93:    added all of the calls required to support the "Getting 
  7.  --                                    Started with QuickDraw™ GX" session at the WWDC '93     
  8.  --
  9.  --                            8/93:    updated file to work with the ß2 "GXified" interface files
  10.  --            
  11.  --
  12.  --        File:        Getting Started GX - misc.c
  13.  --
  14.  --
  15.  --        Comments:    This file contains utility and menu handling routines.
  16.  --
  17.  --
  18.  --        Components:    Getting Started GX - main.c
  19.  --                    Getting Started GX - main.h
  20.  --                    Getting Started GX - shapes.c
  21.  --                    Getting Started GX - printing.c
  22.  --                    Getting Started GX - misc.c
  23.  --                    Getting Started QD GX.π.rsrc
  24.  --
  25.  --                    The file titled: "Getting Started GX - main.c" contains the code required to
  26.  --                    intialize and tear down the QuickDraw GX world, and the event loop.
  27.  --
  28.  --                    The file titled: "Getting Started GX - shapes.c" contains of the code used to 
  29.  --                    create and manipulate the shapes draw into the window.
  30.  --        
  31.  --                    The file titled: "Getting Started GX - printing.c" contains of the code used to 
  32.  --                    print the contents of  the window.
  33.  --        
  34.  --        
  35.  --        QuickDraw GX
  36.  --        Libraries
  37.  --        Used:        This application uses the following QuickDraw GX library code files:
  38.  --                    "color library.c", "font library.c", "graphics debug library.c",
  39.  --                    "layout library.c", "qd library.c", "shape library.c", 
  40.  --                    "transferMode library.c", and "transform library.c". 
  41.  --        
  42.  --        
  43.  --        Notes:        1) Print this file in landscape for the best results
  44.  --                    2) If you are using THINK C v5.x, I have added THINK markers to navigate the code.
  45.  --                    3) This code was adapted from the "Banana Jr." QuickDraw GX sample.
  46.  --
  47.  --
  48.  --        Author:        Pete "Luke" Alexander
  49.  --                    Developer Technical Support
  50.  --                    AppleLink: DEVSUPPORT
  51.  --
  52.  --        
  53.  --        ©1992 - 1993  Apple Computer, Inc. 
  54.  --        All rights reserved.
  55.  --
  56.  **/
  57.  
  58. #include <Desk.h>
  59. #include <Menus.h>
  60.  
  61.  
  62. #include <GXEnvironment.h>
  63. #include "GraphicsLibraries.h"
  64. #include <GXPrinting.h>
  65. #include "Getting Started GX - main.h"
  66.  
  67.  
  68. /*------ DoMenuCommand ---------------------------------------------------------------------------------------*/
  69. //
  70. //    This routine handles the dispatching of our menu requests.
  71. //
  72. void DoMenuCommand(long menuResult)
  73. {
  74.     short                menuID;
  75.     short                menuItem;
  76.     Str255                daName;
  77.     OSErr                err;
  78.     gxDialogResult        result;
  79.     
  80.     menuID = menuResult >>16;
  81.     menuItem = menuResult & 0x0000ffff;
  82.     
  83.     switch (menuID)
  84.     {
  85.         case mApple:
  86.             switch (menuItem)
  87.             {
  88.                 case iAbout:        /* display About box */
  89.                     break;
  90.                 
  91.                 default:            /* handle DA selection */
  92.                     GetItem(GetMHandle(mApple), menuItem, daName);
  93.                     OpenDeskAcc(daName);
  94.                     break;
  95.             }
  96.             break;
  97.             
  98.             case mFile:
  99.                 switch (menuItem)
  100.                 {                        
  101.                     case iNew:
  102.                             /* create new window */
  103.                             
  104.                                 err = DoCreateNew();
  105.                         break;
  106.                                                 
  107.                     case iOpen:
  108.                             /* open saved window */
  109.                             
  110.                         break;
  111.                                                 
  112.                     case iClose:
  113.                             /* close front window */
  114.                             
  115.                                 DoDispose(FrontWindow());
  116.                         break;
  117.                                                 
  118.                     case iSave:
  119.                             /* save front window */
  120.                             
  121.                         break;
  122.                                                 
  123.                     case iPrintOne:
  124.                             /* perform print-one */
  125.                             
  126.                             err = DoPrintOneCopy(FrontWindow());
  127.                         break;
  128.  
  129.                     case iDocumentSetup:
  130.                             /* perform document setup */
  131.                             
  132.                                 HiliteMenu(0);
  133.                                 err = DoFormat(FrontWindow(), &result);
  134.                         break;
  135.     
  136.                     case iByPageSetup:
  137.                             /* perform by page setup */
  138.                                 HiliteMenu(0);
  139.                         break;
  140.                                                 
  141.                         
  142.                     case iPrint:
  143.                             /* perform print */
  144.                             
  145.                                 HiliteMenu(0);
  146.                                 err = DoPrinting(FrontWindow());
  147.                         break;
  148.  
  149.                     case iQuit:
  150.                         gQuitting = true;
  151.                         break;
  152.                 }
  153.                 break;
  154.                 
  155.             case mEdit:
  156.                 break;
  157.                 
  158.             case mGraphics:
  159.                 switch (menuItem)
  160.                 {                        
  161.                     case iCreateABlackRectangle:
  162.                         CreateABlackRectangle (FrontWindow());
  163.                         break;
  164.                         
  165.                     case iColorTheRectangle:
  166.                         ColorTheRectangle (FrontWindow());
  167.                         break;
  168.                         
  169.                     case iCreateAQ:
  170.                         CreateAQ(FrontWindow());
  171.                         break;
  172.                         
  173.                     case iOutlineTheQ:
  174.                         OutlineTheQ(FrontWindow());
  175.                         break;
  176.                         
  177.                     case iCreateAD:
  178.                         CreateAD(FrontWindow());
  179.                         break;
  180.                         
  181.                     case iCreateAG:
  182.                         CreateAG(FrontWindow());
  183.                         break;
  184.                         
  185.                     case iCreateAX:
  186.                         CreateAX(FrontWindow());
  187.                         break;
  188.                 }
  189.                 break;
  190.                 
  191.             case mTypography:
  192.                 switch (menuItem)
  193.                 {                        
  194.                     case iCreateLayout:
  195.                         CreateNewLayoutShape (FrontWindow());
  196.                         break;
  197.                         
  198.                     case iAddKanjiToLayout:
  199.                         AddKanjiToLayout (FrontWindow());
  200.                         break;
  201.                         
  202.                     case iPerspectLayout:
  203.                         PerspectLayout(FrontWindow());
  204.                         break;
  205.                 }
  206.                 break;
  207.  
  208.     }
  209.     HiliteMenu(0);
  210. }
  211.  
  212.  
  213.  
  214. /*------ GetDocShape ---------------------------------------------------------------------------------*/
  215. //
  216. //    This utility routine returns the page shape (contents) attached to a window's document.
  217. //
  218. gxShape GetDocShape(WindowPtr wind)
  219. {
  220.     TH_Doc    doc;
  221.     gxShape    docPage = nil;
  222.  
  223.     if (wind)
  224.     {
  225.         doc = (TH_Doc) GetWRefCon(wind);
  226.         docPage = (*doc)->docPage;
  227.     }
  228.     
  229.     return docPage;
  230. }
  231.  
  232.  
  233. /*------ GetDocJob -----------------------------------------------------------------------------------*/
  234. //
  235. //    This utility routine returns the print job attached to a window's document.
  236. //
  237. gxJob GetDocJob(WindowPtr wind)
  238. {
  239.     TH_Doc    doc;
  240.     gxJob    docJob = nil;
  241.  
  242.     if (wind)
  243.     {
  244.         doc = (TH_Doc) GetWRefCon(wind);
  245.         docJob = (*doc)->docJob;
  246.     }
  247.     
  248.     return docJob;
  249. }
  250.